package cn.kgc.ssm.service.impl;

import cn.kgc.ssm.entity.LogInfo;
import cn.kgc.ssm.mapper.LogInfoMapper;
import cn.kgc.ssm.service.LogInfoService;
import cn.kgc.ssm.utils.ResponseResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/3/9
 * @description
 */
@Service
public class LogInfoServiceImpl implements LogInfoService {

    @Resource
    private LogInfoMapper logInfoMapper;

    @Override
    public void add(LogInfo logInfo) {
        logInfoMapper.insertLog(logInfo);
    }

    @Override
    public ResponseResult logsPage(Integer page, Integer limit, String description, String model) {

        PageHelper.startPage(page, limit);

        List<LogInfo> logInfos = logInfoMapper.selectList(description, model);

        PageInfo<LogInfo> logInfoPageInfo = new PageInfo<>(logInfos);

        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(0);
        responseResult.setCount(logInfoPageInfo.getTotal());
        responseResult.setData(logInfos);
        responseResult.setMsg("查询成功");

        return responseResult;
    }

    @Override
    public ResponseResult deleteLogs(Integer[] ids) {
        logInfoMapper.deleteLogInfo(ids);

        ResponseResult responseResult = new ResponseResult();
        responseResult.setMsg("删除成功");
        responseResult.setCode(0);
        return responseResult;
    }
}
